<%--
  Created by IntelliJ IDEA.
  User: sherlockholmes
  Date: 22/04/2020
  Time: 3:52 AM
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=utf-8" language="java" isELIgnored="false" pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>SpringMVC-SSS</title>
    <script type="text/javascript" src="/js/jquery.min.js"></script>

    <script>
        function isNull( str ){
            if ( str == "" ) return true;
            var regu = "^[ ]+$";
            var re = new RegExp(regu);
            return re.test(str);
        }
        $(function () {

            $("#ajaxBtn").bind("click",function () {
                var id = $('#id').val().trim();
                if(isNull(id)){
                    id = null;
                }else{
                    id = parseInt(id);
                }
                var json = {"id": id, "name": $('#name').val().trim(),
                    "address":$('#address').val().trim(), "phone":$('#phone').val().trim()}
                // 发送ajax请求
                $.ajax({
                    url: '/addOrUpdate',
                    type: 'POST',
                    data: JSON.stringify(json),
                    contentType: 'application/json;charset=utf-8',
                    dataType: 'json',
                    success: function (data) {
                        location.href="/list"
                    }
                })

            })


        })
    </script>
</head>
<body>
    <div>
<%--        <h2>添加或更新简历</h2>--%>
        <h2>
            <c:if test="${resume==null}">
                添加
            </c:if>
            <c:if test="${resume!=null}">
                更新
            </c:if>
        </h2>
        <fieldset>
            <p>无ID则为添加，有ID则为更新操作</p>
            <form>
                id: <input id="id" type="text" name="id" value="${resume.id}" disabled="disabled"/>
                name: <input id="name" type="text" name="name" value="${resume.name}" />
                address: <input id="address" type="text" name="address" value="${resume.address}" />
                phone: <input id="phone" type="text" name="phone" value="${resume.phone}" />
                <input type="button" value="提交" id="ajaxBtn" />
            </form>
        </fieldset>
    </div>
</body>
</html>
